package cn.lbz.Food.Edit;

import cn.lbz.Food.Init.DBUtils;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.Serial;
import java.sql.SQLException;


public class DeleteFoodServlet extends HttpServlet{
    @Serial
    private static final long serialVersionUID = -1369131036473739059L;
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        this.doPost(request, response);
    }
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
        String id = request.getParameter("id");
        String sql = "DELETE FROM share_food WHERE id=" + id;

        try {
            DBUtils.delete(sql);
            response.sendRedirect("./editfood");
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
